from django.shortcuts import render
from django.http import HttpResponse,HttpRequest
from django.http import Http404
from rest_framework import status
from rest_framework.views import APIView
from rest_framework import mixins, generics
from rest_framework.response import Response
from api.models import Snippet
from api.serializers import SnippetSerializer

# Create your views here.


class SnippetList(generics.ListCreateAPIView):

    queryset = Snippet.objects.all()
    serializer_class = SnippetSerializer

    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)


class SnippetDetail(generics.RetrieveUpdateDestroyAPIView):
    """
    Retrieve, update or delete a snippet instance.
    """

    queryset = Snippet.objects.all()
    serializer_class = SnippetSerializer
